Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: ethernet: ksz8081: streamline codebase #81816

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ndrs-pst
Copy link
Contributor

This PR includes the following improvements:

  • Simplify error handling in phy_mc_ksz8081_get_link()
  • Simplify GPIO reset logic in phy_mc_ksz8081_reset()

Simplifies error handling in `phy_mc_ksz8081_get_link()` by
centralizing mutex unlocking with a `done` label.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
Simplifies GPIO reset logic in `phy_mc_ksz8081_reset()` by
operating within a conditional block, allowing the removal of
the `skip_reset_gpio` label.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
@@ -283,27 +276,27 @@ static int phy_mc_ksz8081_reset(const struct device *dev)
}

#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
if (!config->reset_gpio.port) {
goto skip_reset_gpio;
Copy link
Member

@decsny decsny Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of the PR is good but I preferred the negative check here to avoid the extra indentation (ie keeping indentation strictly max of 2 indents), maybe would be better to make the gpio reset into a helper function, like:

#if DT_ANY_INST_HAS_PROP_STATUS_OKAY
static int phy_ksz8081_reset_gpio(config *)
{
  int ret;

  if (!config->reset_gpio.port) {
    return 0;
  }

  /* rest of reset code */
  return ret;
}
#else 
#define phy_ksz8081_reset_gpio(...)
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing helper functions might cause ambiguity between a missing GPIO port (returning 0) and a successful GPIO operation (also returning 0).
Adding extra return values to differentiate them would complicate the code.

Given the constraint of maintaining a max of 2 indents, I suggest reverting to the previous code structure but improving it by moving const struct mc_ksz8081_config *config = dev->config; inside the #if block.

WDYT? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already silence if there's a missing gpios port, maybe what you want to do is add some kind of log message

Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants